package com.bjbn.controller;

import com.bjbn.bean.MonitorResponse;
import com.bjbn.bean.TopicInfo;
import com.bjbn.service.ActivemqMonitorService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * ActiveMQ监控控制器
 * 
 * @author bjbn
 */
@Slf4j
@RestController
@RequestMapping("/api/monitor")
@CrossOrigin(origins = "*")
public class ActivemqMonitorController {

    @Autowired
    private ActivemqMonitorService monitorService;

    /**
     * 获取所有Topic的监控状态
     * 
     * @return 监控响应
     */
    @GetMapping("/status")
    public MonitorResponse getMonitorStatus() {
        log.info("获取ActiveMQ监控状态");
        return monitorService.getMonitorStatus();
    }

    /**
     * 获取指定Topic的监控状态
     * 
     * @param topicName Topic名称
     * @return Topic信息
     */
    @GetMapping("/topic/{topicName}")
    public TopicInfo getTopicStatus(@PathVariable String topicName) {
        log.info("获取Topic {} 的监控状态", topicName);
        return monitorService.getTopicStatus(topicName);
    }

    /**
     * 获取所有Topic信息列表
     * 
     * @return Topic信息列表
     */
    @GetMapping("/topics")
    public List<TopicInfo> getAllTopics() {
        log.info("获取所有Topic信息列表");
        return monitorService.getAllTopics();
    }

    /**
     * 健康检查接口
     * 
     * @return 健康状态
     */
    @GetMapping("/health")
    public String health() {
        return "ActiveMQ Monitor Service is running";
    }

    /**
     * 首页接口
     * 
     * @return 欢迎信息
     */
    @GetMapping("/")
    public String index() {
        return "ActiveMQ数据推送监控服务已启动，请访问 /api/monitor/status 查看监控状态";
    }
} 